package com.yyq.adms.yyb.commonlink.action;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionContext;
import com.yyq.adms.yyb.commonlink.bpo.CommonLinkBpo;
import com.yyq.adms.yyb.commonlink.pojo.CommonLink;
import com.yyq.sos.action.BaseAction;
import com.yyq.sos.constants.ActionType;
import com.yyq.sos.constants.Constants;
import com.yyq.sos.permission.LoginUser;
import com.yyq.sos.util.PermissionsUtil;

/**
 * 常用链接Action
 * @author 杨应滨
 * @2012-12-14
 *
 */
@Controller("CommLinkAction")
@Scope("prototype")
public class CommonLinkAction extends BaseAction{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private CommonLink po = new CommonLink();
	
	private CommonLinkBpo bpo;
	
	private String param;
	
	
	public CommonLink getPo() {
		return po;
	}

	public void setPo(CommonLink po) {
		this.po = po;
	}

	public CommonLinkBpo getBpo() {
		return bpo;
	}

	@Resource(name="CommonLinkBpo")
	public void setBpo(CommonLinkBpo bpo) {
		bpo.setCls(po.getClass());
		this.bpo = bpo;
	}

	public static long getSerialversionuid() {
		return serialVersionUID;
	}

	
	public String execute()throws Exception
	{
		super.setBpo(bpo);
		super.setObj(po);
		String s = super.execute();
		this.setPo((CommonLink)super.getObj());
		return s;
	}
	
	
	@Override
	public String data() {
		
		//LoginUser user = (LoginUser)this.getSession().getAttribute(Constants.LOGIN_USER);
		//String moduleName = getModuleName(this.getRequest().getRequestURI());
		//boolean isPerm = PermissionsUtil.checkPermissionByCode(this.getSession(), moduleName,Constants.RIGHT_GLOBAL);
		String hql = "";
		//if(user.getUserId().intValue()==1 || isPerm){
			hql = "from CommonLink where belongModel = '"+param+"'";
		/*}else{
			hql = "from "+po.getClass().getName()+" obj where (obj.maintainDep="+user.getOrgId()+" or EXISTS(from RecordSentDep rsd where obj.id=rsd.sourceRecordId and rsd.sentDepId="+user.getOrgId()+")) and obj.belongModel = '"+param+"'";
		}*/
		this.setFormData(bpo.searchPage(hql, getPageForm().getPageNo(), getPageForm().getPageSize()));
		List _list = getData();
		for(int i = 0; i < _list.size(); i ++) {
			CommonLink _commonLink = (CommonLink)_list.get(i);
			String path = _commonLink.getPath();
			System.out.println(path);
			if(!path.startsWith("http")) {
				((CommonLink)_list.get(i)).setPath("http:\\\\" + path);
			}
		}
		setData(_list);
		return ActionType.ACTION_DATA_LIST;
	}
	
	public String getParam() {
		return param;
	}

	public void setParam(String param) {
		this.param = param;
	}
	
	@Override
	public void setTreeNodeSession() {
		try {
			param = new String(param.getBytes(), "GBK");  
			param = param.replaceAll(" ", "");
		} catch(Exception e) {
			
		}
		ActionContext.getContext().getSession().put("treeNodeName", param);
	}

	
	
	

	
	
	
	

}
